package com.miao.hong.fang.util.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AccssFilter implements Filter {

	 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		 
		 HttpServletRequest hReq = (HttpServletRequest) request;
	     HttpServletResponse hRes = (HttpServletResponse) response;
	     
	     String uri = hReq.getRequestURI();
	     if(!uri.endsWith("index.jsp")) {
	    	 if(uri.endsWith(".jsp")) {
	    		 hRes.sendRedirect(hReq.getContextPath() + "/index.jsp");
	    	 }
	     }
	     chain.doFilter(hReq, hRes);
	     
	     
	     System.out.println("This is the filter after processing by servlet");
	 }

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		
	}
}
